package com.common;

import com.constant.ResultEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
@AllArgsConstructor

//统一返回结果的类
public class Result<T> {

    private int  code;     //返回码
    private  String msg;  //返回消息
    private T data;


    //成功
    public  Result<T>  setSuc(T data){
        this.setCode(ResultEnum.SUCCESS.getCode());
        this.setMsg(ResultEnum.SUCCESS.getMsg());
        this.setData(data);
        return this;
    }

    public   Result setSuc(){
        // this.setCode(ResultEnum.SUCCESS.getCode());
        // this.setMsg(ResultEnum.SUCCESS.getMsg());
        // this.setData(null);
        return setSuc(null);
    }

    public  Result setFail(ResultEnum resultEnum){
        return setFail(resultEnum.getCode(),resultEnum.getMsg());
    }

    public Result setFail(String msg){
        this.setCode(-1);
        this.setMsg(msg);
        this.setData(null);
        return this;
    }
    public  Result setFail(int code, String msg){
        this.setCode(code);
        this.setMsg(msg);
        this.setData(null);
        return this;
    }
}
